package com.sugar.psych.assessment.module.business.controller.admin.userleavemessageliked;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.sugar.psych.assessment.framework.common.pojo.PageParam;
import com.sugar.psych.assessment.framework.common.pojo.PageResult;
import com.sugar.psych.assessment.framework.common.pojo.CommonResult;
import com.sugar.psych.assessment.framework.common.util.object.BeanUtils;
import static com.sugar.psych.assessment.framework.common.pojo.CommonResult.success;

import com.sugar.psych.assessment.framework.excel.core.util.ExcelUtils;

import com.sugar.psych.assessment.framework.apilog.core.annotation.ApiAccessLog;
import static com.sugar.psych.assessment.framework.apilog.core.enums.OperateTypeEnum.*;

import com.sugar.psych.assessment.module.business.controller.admin.userleavemessageliked.vo.*;
import com.sugar.psych.assessment.module.business.dal.dataobject.userleavemessageliked.UserLeaveMessageLikedDO;
import com.sugar.psych.assessment.module.business.service.userleavemessageliked.UserLeaveMessageLikedService;

@Tag(name = "管理后台 - 用户留言点赞")
@RestController
@RequestMapping("/business/user-leave-message-liked")
@Validated
public class UserLeaveMessageLikedController {

    @Resource
    private UserLeaveMessageLikedService userLeaveMessageLikedService;

    @PostMapping("/create")
    @Operation(summary = "创建用户留言点赞")
    @PreAuthorize("@ss.hasPermission('business:user-leave-message-liked:create')")
    public CommonResult<Long> createUserLeaveMessageLiked(@Valid @RequestBody UserLeaveMessageLikedSaveReqVO createReqVO) {
        return success(userLeaveMessageLikedService.createUserLeaveMessageLiked(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新用户留言点赞")
    @PreAuthorize("@ss.hasPermission('business:user-leave-message-liked:update')")
    public CommonResult<Boolean> updateUserLeaveMessageLiked(@Valid @RequestBody UserLeaveMessageLikedSaveReqVO updateReqVO) {
        userLeaveMessageLikedService.updateUserLeaveMessageLiked(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除用户留言点赞")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('business:user-leave-message-liked:delete')")
    public CommonResult<Boolean> deleteUserLeaveMessageLiked(@RequestParam("id") Long id) {
        userLeaveMessageLikedService.deleteUserLeaveMessageLiked(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除用户留言点赞")
                @PreAuthorize("@ss.hasPermission('business:user-leave-message-liked:delete')")
    public CommonResult<Boolean> deleteUserLeaveMessageLikedList(@RequestParam("ids") List<Long> ids) {
        userLeaveMessageLikedService.deleteUserLeaveMessageLikedListByIds(ids);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得用户留言点赞")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('business:user-leave-message-liked:query')")
    public CommonResult<UserLeaveMessageLikedRespVO> getUserLeaveMessageLiked(@RequestParam("id") Long id) {
        UserLeaveMessageLikedDO userLeaveMessageLiked = userLeaveMessageLikedService.getUserLeaveMessageLiked(id);
        return success(BeanUtils.toBean(userLeaveMessageLiked, UserLeaveMessageLikedRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得用户留言点赞分页")
    @PreAuthorize("@ss.hasPermission('business:user-leave-message-liked:query')")
    public CommonResult<PageResult<UserLeaveMessageLikedRespVO>> getUserLeaveMessageLikedPage(@Valid UserLeaveMessageLikedPageReqVO pageReqVO) {
        PageResult<UserLeaveMessageLikedDO> pageResult = userLeaveMessageLikedService.getUserLeaveMessageLikedPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, UserLeaveMessageLikedRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出用户留言点赞 Excel")
    @PreAuthorize("@ss.hasPermission('business:user-leave-message-liked:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportUserLeaveMessageLikedExcel(@Valid UserLeaveMessageLikedPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<UserLeaveMessageLikedDO> list = userLeaveMessageLikedService.getUserLeaveMessageLikedPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "用户留言点赞.xls", "数据", UserLeaveMessageLikedRespVO.class,
                        BeanUtils.toBean(list, UserLeaveMessageLikedRespVO.class));
    }

}